package com.kaikeba.spring.aop;

import org.aopalliance.intercept.Joinpoint;
import org.aspectj.lang.ProceedingJoinPoint;

public class TimeAdvice {

	public Object aroundTime(ProceedingJoinPoint jointPoint) {
		Object result = null;
		try {
			System.out.println("环绕通知开始 时间记录");
			long start = System.currentTimeMillis();
			//获取方法执行所需参数
			Object[] args = jointPoint.getArgs();
			// 有返回参数 则需返回值
			result = jointPoint.proceed(args);
			String className = jointPoint.getTarget().getClass().getSimpleName();
			String methodName = jointPoint.getSignature().getName();
			long end = System.currentTimeMillis();
			System.out.println(className+"类的"+" 方法:"+methodName+" 总共执行时长" + (end - start) + " 毫秒");
			System.out.println("环绕通知结束 时间记录");
		} catch (Throwable t) {
			System.out.println("出现错误");
		}
		return result;
	}

}
